<%@ page language="java" contentType="text/html;charset=UTF-8" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack"%>

<chiptrack:checkLogon sourcePage="searchMetaData.do"/>
<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</script>
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<SCRIPT language="JavaScript">
    function closeWindow()
    {
        window.opener.search();
        window.close();
    }
    var noOfRows = 0;
    function save()
    {
        errors1 = "";
        var form = document.searchMetaDataForm;
        for ( var i = 0; i < noOfRows; i++ )
        {
            if ( form['columnMetaDataList['+i+'].order'].value == "" )
            {
                errors1=errors1+"<li>Please enter value for Order"
            }
            else if ( form['columnMetaDataList['+i+'].order'].value == "0" )
            {
                errors1=errors1+"<li>Order can not be zero"
            }
            else if ( Number( form['columnMetaDataList['+i+'].order'].value ) > noOfRows  )
            {
                errors1=errors1+"<li>Order can not be greater than "+noOfRows
            }
            if ( errors1 != "" )
            {
                form['columnMetaDataList['+i+'].order'].select();
                form['columnMetaDataList['+i+'].order'].focus();
                break;
            }
        }
        for ( i = 0; i < noOfRows; i++ )
        {
            var cnt = 0;
            var dispName1 =  trim ( form['columnMetaDataList[' + i + '].displayName'].value )

            if ( dispName1 != '' )
            {
                for ( j = i + 1; j < noOfRows; j++ )
                {
                    var dispName2= trim ( form['columnMetaDataList[' + j + '].displayName'].value )
                    if ( dispName1.toUpperCase() == dispName2.toUpperCase() )
                    {
                        cnt = cnt + 1;
                    }
                    if ( cnt > 0 )
                    {
                        form['columnMetaDataList[' + i + '].displayName'].select();
                        form['columnMetaDataList[' + i + '].displayName'].focus();
                        errors1 ="<li>Display Name has duplicates</li>"
                        break;
                    }
                }
                if ( cnt > 0 )
                    break;
            }
            else
            {
                form['columnMetaDataList[' + i + '].displayName'].select();
                form['columnMetaDataList[' + i + '].displayName'].focus();
                errors1 ="<li>Display Name cann't be empty</li>"
                break;
            }
        }

        if ( errors1 == '' )
        {
            document.searchMetaDataForm.action.value="save";
            document.searchMetaDataForm.submit();
        }
        else
        {
            var pa = document.getElementById("messageId");
            pa.innerHTML = ""
            pa = document.getElementById("error");
            pa.innerHTML = errors1
        }
    }
</SCRIPT>
<html:form name="searchMetaDataForm" method="post"  action="/searchMetaData.do" scope="session" type="com.scalar.forecast.columnDisplay.forms.SearchMetaDataForm" >
<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
    <TBODY>
    <TR>
	    <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'></TD>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="100%">

        <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
        <BR>
<!-- from here your body starts -->
            <center><span class="NArialW">Edit Column Display</span></center>
            <table border="0" width="100%" cellpadding=0 cellspacing=0 align="center">
                <tr>
                    <td align=right>  <a href="javascript:closeWindow();"  onMouseOver="window.status='Click here to close this window';return true" title="Click here to close this window"><font class='NArialL'><b>[Close this window]</b></font></a> </td>
                </tr>
                <tr>
                    <td>
                        <table width="95%" class="NArialL" align="center" border="0" >
                            <TR><TD class="NArialL" colspan="3" id="messageId"><chiptrack:messages type="info" styleClass="NArialL" />&nbsp;</TD></TR>
                            <TR><TD class="NArialL" colspan="3"><FONT COLOR="RED" id="error">&nbsp;</FONT></TD></TR>
                            <tr bgcolor='#993333' class="NArialL" align="middle">
                                <td width="38%"><font color='#FFFFFF'>&nbsp;Column Name</font></td>
                                <td width="38%"><font color='#FFFFFF'>&nbsp;Display Name</font></td>
                                <td width="15%"><font color='#FFFFFF'>&nbsp;Order</font></td>
                            </tr>
                            <% int rowCnt=0; %>
                            <nested:iterate property="columnMetaDataList" id="columnMetaData">
                            <% rowCnt++; %>
                            <tr bgcolor='#DEE1E2' class="NArialL">
                                <nested:hidden property="rowId"/>
								<td width="38%"><FONT class=NArialL><bean:write name="columnMetaData" property="columnName"/></FONT></td>
								<td width="38%"><nested:text name="columnMetaData" property="displayName" styleClass="txfield" size="25" maxlength="50"/></td>
								<td width="15%"><nested:text name="columnMetaData" property="order" styleClass="txfield" size="10" maxlength="3" onkeypress="javaScript:allowInteger();"/></td>
							</tr>
                            </nested:iterate>
                            <script>noOfRows=<%=rowCnt%>;</script>
                            <tr><td colspan=3>&nbsp;</td></tr>
                        </table>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td align="center">
                        <a href="javascript:save();" onmouseover="window.status='Click here to Save';return true" title="Click here to Save" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a>&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:document.searchMetaDataForm.reset();" onmouseover="window.status='Click here to Reset';return true" title="Click here to Reset" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>&nbsp;&nbsp;&nbsp;&nbsp;
                        <%--<a href="javascript:closeWindow();" ><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17" onMouseOver="window.status='Click here to close this window';return true" title="Click here to close this window"></a>--%>
                    </td>
                </tr>
                <tr class="NArialL"><td>&nbsp;</td></tr>
                <tr><td>&nbsp;</td></tr>
            </table>
        <input type="hidden" name="action" value="">
        </html:form>
<!-- till here -->
        <TD>
    </TR>
    </TBODY>
</TABLE>
</BODY>
</HTML>


